// src/main.js
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import { router } from '@/router/index'
import { useAuthStore } from './stores/auth'

// ✅ 正确导入 ElementPlus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

// ✅ 导入 Vant 组件和样式
import 'vant/lib/index.css'
import "vant/es/toast/style"

// ✅ 从正确的包导入图标
import {
  ArrowRight,
  Edit,
  Delete,
  Plus,
  Search,
  HomeFilled,
  Promotion
} from '@element-plus/icons-vue'

const app = createApp(App)
const pinia = createPinia()

// 使用 Pinia 和 Router
app.use(pinia)
app.use(router)
app.use(ElementPlus) // ✅ 使用 ElementPlus 插件

// 🌟 全局注册图标组件
const icons = [ArrowRight, Edit, Delete, Plus, Search, HomeFilled, Promotion]
icons.forEach(icon => {
  app.component(icon.name, icon)
})

// 🔁 注意：ImagePreview 不应该 use，直接在组件中调用

// 初始化认证状态
const authStore = useAuthStore()
authStore.initUser().then(() => {
  app.mount('#app')
})
